package com.the8thfold.anton.services

import com.the8thfold.anton.ant.AntJobRunResults

class NotificationsService {

    def mailService
    def settingsService

    static transactional = true

    def notifyRunResult(AntJobRunResults result) {
        settingsService.updateMailSettings()

        //from "ANTON<no-reply@the8thfold.com>"
        if (result.notifiedUsers){
            def notifiedToList = []
            notifiedToList = result.notifiedUsers.collect {it.emailAddress} as List

            mailService.sendMail {
                from "ANTON<master@the8thfold.com>"
                to notifiedToList.toArray()
                subject "Anton: ${result.name}"
                html """Hi,
                    The following Anton Job Run is completed:<br/>
                    <a href="http://localhost:8090/anton/result/${result.runResultsId}/view">${result.name}</a>
                """

            }
        }
    }
}
